package com.leyou.item.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.item.dto.CategoryDTO;
import com.leyou.item.entity.Category;
import com.leyou.item.mapper.CategoryMapper;
import com.leyou.item.service.CategoryService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {


    @Override
    public List<CategoryDTO> queryCategoryByPid(Long pid) {

        //select * from tb_category where parent_id = #{pid};

        List<Category> categories = query().eq("parent_id", pid).list();

        //把查询到的实体entity的集合转换为dto的集合

        return CategoryDTO.convertEntityList(categories);
    }

    @Override
    public CategoryDTO queryCategoryById(Long id) {

        return new CategoryDTO(this.getById(id));
    }

    @Override
    public List<CategoryDTO> queryCategoryByIds(List<Long> ids) {

        //select * from tb_category where id in(1,2,4,5)

        return CategoryDTO.convertEntityList(listByIds(ids));
    }

    @Override
    public List<CategoryDTO> queryCategoryByBrand(Long bid) {

        return CategoryDTO.convertEntityList(this.getBaseMapper().queryCategoryByBrandId(bid));
    }
}
